package top.glkj.hms.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description 配置类
 * @Author xgl
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2020/1/3
 */
@Slf4j
@SpringBootConfiguration
public class MyWebConfig implements WebMvcConfigurer {
    //@Override
    //public void addCorsMappings(CorsRegistry registry) {
    //    //所有请求都允许跨域，使用这种配置方法就不能在 interceptor 中再配置 header 了
    //    registry.addMapping("/**")
    //            .allowCredentials(true)
    //            .allowedOrigins("0.0.0.0/0")
    //            .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
    //            .allowedHeaders("*")
    //            .maxAge(3600);
    //}

    @Value("${file.staticAccessPath}")
    private String staticAccessPath;
    @Value("${file.uploadFolder}")
    private String uploadFolder;
    @Value("${file.staticPath}")
    private String staticPath;
    @Value("${file.uploadFile}")
    private String uploadFile;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + uploadFolder);
        log.info(staticAccessPath);
        log.info(uploadFolder);
        log.info(staticPath);
        log.info(uploadFile);
        registry.addResourceHandler(staticPath).addResourceLocations("file:" + uploadFile);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

    }
}
